﻿using System; 
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic; 
using System.Data;
using DingTalkAgent.DBUtility;
namespace DingTalkAgent.SqlData  
{
	 	//违规l流转记录
		public partial class progresslLog
	{
	#region	 T_progresslLog
	
	///<summary>
	/// Exist
	///</summary>
	public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_progresslLog");
			strSql.Append(" where ");
			                                       strSql.Append(" id = @id  ");
                            			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}
		
				
		
		/// <summary>
		/// 增加一条T_progresslLog数据
		/// </summary>
		public int Add(DingTalkAgent.Model.progresslLog model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_progresslLog(");			
            strSql.Append("IlLogid,rowCount,acceptType,acceptUO,TelegraphMsg,TelegraphTimee,Telegraphuserid,reamrk");
			strSql.Append(") values (");
            strSql.Append("@IlLogid,@rowCount,@acceptType,@acceptUO,@TelegraphMsg,@TelegraphTimee,@Telegraphuserid,@reamrk");            
            strSql.Append(") ");            
            strSql.Append(";select @@IDENTITY");		
			SqlParameter[] parameters = {
			            new SqlParameter("@IlLogid", SqlDbType.Int,4) ,            
                        new SqlParameter("@rowCount", SqlDbType.Int,4) ,            
                        new SqlParameter("@acceptType", SqlDbType.VarChar,64) ,            
                        new SqlParameter("@acceptUO", SqlDbType.VarChar,64) ,            
                        new SqlParameter("@TelegraphMsg", SqlDbType.VarChar,256) ,            
                        new SqlParameter("@TelegraphTimee", SqlDbType.DateTime) ,            
                        new SqlParameter("@Telegraphuserid", SqlDbType.VarChar,64) ,            
                        new SqlParameter("@reamrk", SqlDbType.VarChar,2048)             
              
            };
			            
            parameters[0].Value = model.IlLogid;                        
            parameters[1].Value = model.rowCount;                        
            parameters[2].Value = model.acceptType;                        
            parameters[3].Value = model.acceptUO;                        
            parameters[4].Value = model.TelegraphMsg;                        
            parameters[5].Value = model.TelegraphTimee;                        
            parameters[6].Value = model.Telegraphuserid;                        
            parameters[7].Value = model.reamrk;                        
			   
			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);			
			if (obj == null)
			{
				return 0;
			}
			else
			{
				                    
            	return Convert.ToInt32(obj);
                                                                  
			}			   
            			
		}
		
		
		/// <summary>
		/// 更新一条T_progresslLog数据
		/// </summary>
		public bool Update(DingTalkAgent.Model.progresslLog model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_progresslLog set ");
			                                                
            strSql.Append(" IlLogid = @IlLogid , ");                                    
            strSql.Append(" rowCount = @rowCount , ");                                    
            strSql.Append(" acceptType = @acceptType , ");                                    
            strSql.Append(" acceptUO = @acceptUO , ");                                    
            strSql.Append(" TelegraphMsg = @TelegraphMsg , ");                                    
            strSql.Append(" TelegraphTimee = @TelegraphTimee , ");                                    
            strSql.Append(" Telegraphuserid = @Telegraphuserid , ");                                    
            strSql.Append(" reamrk = @reamrk  ");            			
			strSql.Append(" where id=@id ");
						
SqlParameter[] parameters = {
			            new SqlParameter("@id", SqlDbType.Int,4) ,            
                        new SqlParameter("@IlLogid", SqlDbType.Int,4) ,            
                        new SqlParameter("@rowCount", SqlDbType.Int,4) ,            
                        new SqlParameter("@acceptType", SqlDbType.VarChar,64) ,            
                        new SqlParameter("@acceptUO", SqlDbType.VarChar,64) ,            
                        new SqlParameter("@TelegraphMsg", SqlDbType.VarChar,256) ,            
                        new SqlParameter("@TelegraphTimee", SqlDbType.DateTime) ,            
                        new SqlParameter("@Telegraphuserid", SqlDbType.VarChar,64) ,            
                        new SqlParameter("@reamrk", SqlDbType.VarChar,2048)             
              
            };
			            
            parameters[0].Value = model.id;                        
            parameters[1].Value = model.IlLogid;                        
            parameters[2].Value = model.rowCount;                        
            parameters[3].Value = model.acceptType;                        
            parameters[4].Value = model.acceptUO;                        
            parameters[5].Value = model.TelegraphMsg;                        
            parameters[6].Value = model.TelegraphTimee;                        
            parameters[7].Value = model.Telegraphuserid;                        
            parameters[8].Value = model.reamrk;                        
            int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		
		/// <summary>
		/// 删除一条T_progresslLog数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_progresslLog ");
			strSql.Append(" where id=@id");
						SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;


			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
				/// <summary>
		/// 删除一条T_progresslLog数据
		/// </summary>
		public bool Deletes(string ids )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_progresslLog ");
			strSql.Append(" where ID in ("+ids + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
				
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DingTalkAgent.Model.progresslLog GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id, IlLogid, rowCount, acceptType, acceptUO, TelegraphMsg, TelegraphTimee, Telegraphuserid, reamrk  ");			
			strSql.Append("  from T_progresslLog ");
			strSql.Append(" where id=@id");
						SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

			
			DingTalkAgent.Model.progresslLog model=new DingTalkAgent.Model.progresslLog();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			
			if(ds.Tables[0].Rows.Count>0)
			{
												if(ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["IlLogid"].ToString()!="")
				{
					model.IlLogid=int.Parse(ds.Tables[0].Rows[0]["IlLogid"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["rowCount"].ToString()!="")
				{
					model.rowCount=int.Parse(ds.Tables[0].Rows[0]["rowCount"].ToString());
				}
																																				model.acceptType= ds.Tables[0].Rows[0]["acceptType"].ToString();
																																model.acceptUO= ds.Tables[0].Rows[0]["acceptUO"].ToString();
																																model.TelegraphMsg= ds.Tables[0].Rows[0]["TelegraphMsg"].ToString();
																												if(ds.Tables[0].Rows[0]["TelegraphTimee"].ToString()!="")
				{
					model.TelegraphTimee=DateTime.Parse(ds.Tables[0].Rows[0]["TelegraphTimee"].ToString());
				}
																																				model.Telegraphuserid= ds.Tables[0].Rows[0]["Telegraphuserid"].ToString();
																																model.reamrk= ds.Tables[0].Rows[0]["reamrk"].ToString();
																										
				return model;
			}
			else
			{
				return null;
			}
		}
		
		
		/// <summary>
		/// 获得数据T_progresslLog列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM T_progresslLog ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}
		
		/// <summary>
        /// 获得数据T_progresslLog列表
        /// </summary>
        public IEnumerable<DingTalkAgent.Model.progresslLog> IEnumGetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id, IlLogid, rowCount, acceptType, acceptUO, TelegraphMsg, TelegraphTimee, Telegraphuserid, reamrk ");
            strSql.Append(" FROM T_progresslLog ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            DingTalkAgent.Model.progresslLog model;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                model = new DingTalkAgent.Model.progresslLog();
                								if(dr["id"].ToString()!="")
				{
					model.id=int.Parse(dr["id"].ToString());
				}
																																if(dr["IlLogid"].ToString()!="")
				{
					model.IlLogid=int.Parse(dr["IlLogid"].ToString());
				}
																																if(dr["rowCount"].ToString()!="")
				{
					model.rowCount=int.Parse(dr["rowCount"].ToString());
				}
																																				model.acceptType= dr["acceptType"].ToString();
																																model.acceptUO= dr["acceptUO"].ToString();
																																model.TelegraphMsg= dr["TelegraphMsg"].ToString();
																												if(dr["TelegraphTimee"].ToString()!="")
				{
					model.TelegraphTimee=DateTime.Parse(dr["TelegraphTimee"].ToString());
				}
																																				model.Telegraphuserid= dr["Telegraphuserid"].ToString();
																																model.reamrk= dr["reamrk"].ToString();
																					
                yield return model;
            }
        }
		/// <summary>
        /// 获得数据 T_progresslLog分页列表
        /// </summary>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页大小</param>
        /// <param name="total">总记录数</param>
        /// <param name="keyword">关键字</param>
        /// <returns></returns>
        public List<DingTalkAgent.Model.progresslLog> GetPageList(int PageIndex, int PageSize, out int total,string keyword)
        {
            int Skip = (PageIndex - 1) * PageSize;
            //count
            StringBuilder strSqlCount = new StringBuilder();
            strSqlCount.Append("Select @total=count(id) From T_progresslLog ");
            //data
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Top "+PageSize+" * from (");
           strSql.Append("select  row_number() OVER (ORDER BY id Desc) AS row, id, IlLogid, [rowCount], acceptType, acceptUO, TelegraphMsg, TelegraphTimee, Telegraphuserid, reamrk ");
            strSql.Append(" FROM  T_progresslLog ");
            //where
            StringBuilder Where = new StringBuilder();
            Where.Append(" where 1=1");
            if (keyword.Trim() != "")
            {
                Where.Append(" and (Title like @keyword or content like @keyword) ");
            }
            

            strSqlCount.Append(Where.ToString());
            strSql.Insert(0,strSqlCount.ToString()+";");
            strSql.Append(Where.ToString());
            strSql.Append(") as a ");
            strSql.Append(" Where a.row>"+Skip);

             //parameters
            SqlParameter[] parameters = {
					new SqlParameter("@total", SqlDbType.Int,4),
                    new SqlParameter("@keyword", SqlDbType.VarChar,64)
                    };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = "%" + keyword.Trim() + "%";
            
            List<DingTalkAgent.Model.progresslLog> list = new List<DingTalkAgent.Model.progresslLog>();
            DingTalkAgent.Model.progresslLog model = new DingTalkAgent.Model.progresslLog();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            total = Convert.ToInt32(parameters[0].Value);

             foreach (DataRow dr in ds.Tables[0].Rows)
            {
                model = new DingTalkAgent.Model.progresslLog();
                								if(dr["id"].ToString()!="")
				{
					model.id=int.Parse(dr["id"].ToString());
				}
																																if(dr["IlLogid"].ToString()!="")
				{
					model.IlLogid=int.Parse(dr["IlLogid"].ToString());
				}
																																if(dr["rowCount"].ToString()!="")
				{
					model.rowCount=int.Parse(dr["rowCount"].ToString());
				}
																																				model.acceptType= dr["acceptType"].ToString();
																																model.acceptUO= dr["acceptUO"].ToString();
																																model.TelegraphMsg= dr["TelegraphMsg"].ToString();
																												if(dr["TelegraphTimee"].ToString()!="")
				{
					model.TelegraphTimee=DateTime.Parse(dr["TelegraphTimee"].ToString());
				}
																																				model.Telegraphuserid= dr["Telegraphuserid"].ToString();
																																model.reamrk= dr["reamrk"].ToString();
																					
                list.Add(model);
            }
             return list;
        }
        #endregion
	}
}
